Cloud Cost Comparator Customization

The purpose of this article is to understand the framework of Cloud Cost Comparator Module for further enhancements.

Understanding of the Framework

  • CRON

Maintained a text file which defines the execution frequency of the cron.

  • CSS

All the related CSS files maintained inside this folder.

  • IMAGES

All the necessary images kept inside this folder.

  • JS

All the related JS files maintained inside this folder.

  • JSON

All the required JSON files maintained inside this folder in a hierarchy. First hierarchy maintained based on resources (VM, RDS etc.) and second level hierarchy categorized based on providers.

  • Cron will execute the cloud_download_json.php file periodically and downloads the JSON files from provider API. Need write the logic in this PHP file if any other provider or resource JSON files needs to be downloaded for further enhancement.
  • country_mapping.json is the file which maintains JSON data used by pricing calculator to map provider regions.
  • index.php is landing file for this framework which also includes all the HTML elements and CSS/JS file. In case, wants to add an additional resources, need to alter this file to add HTML elements.
  • This framework loads different HTML filter elements based on resources which requires for comparing prices between different providers.
  • All customized JavaScript related changes placed into file cloudcompare.js. This file handles the AJAX and get processed result based on data searched by a user.
  • Framework maintains different PHP files for the resources which are process_request.php, process_request_rds.php, process_request_elb.php etc. These PHP files processes different providers JSON files based on country mapping, user inputs and generates the final output after processing.
  • addtocart.php processes and maintains Wish list related information.

How to Add an Additional Provider

  1. Create a folder with the provider name inside the resources JSON folder (Ex: JSON -> VM -> AWS ) .
  2. Add the logic into the cloud_download_json.php file for periodic automatic downloads of json files for the newly added provider or manually download the file and place it inside the folder.
  3. Add the provider region mapping details into the file country_mapping.json
  4. Modify the resource based PHP file to fetch and search data from the JSON files for the specific provider. (Ex: To add an additional provider for VM add logic into the file process_request.php)
  5. Define the location of the JSON files path on the top of the processing file ( Ex: define('ROOT_PATH_AWS', './json/vm/aws/') )
  6. Create a configuration array for the newly added provider based on the filters data requires to process the JSON files. (Ex: A variable $config_array used for AWS provider to filter data based on CPU, MEMORY and DISK).
  7. Write logic to fetch data from the JSON file based on country mapping.
  8. Create a closest match function for the newly added provider to process data based on the input filter (Ex: For Azure Provider function used getClosestMatchAzure)
  9. Loop through the configuration array. (Step VI) to call the closest match function to retrieve closest match of the data.
  10. Framework defined a specific range for CPU, MEMROY and DISK, which used to search data within that specific range after finding closest matching data.
  11. Extend the getRangeMatch to add search data within the specific range for the new provider. GetRangeMatch will return the final matched searched result.
  12. Maintain a array to keep the final output for the newly added provider (Ex: Azure final array data_azure_final) and merge array with other providers to retrieve final result.